﻿/***************************
* CLASS PatternLayer
* CREATES A TILEMAP ASSEMBLY
* SCROLLING BY GOTOANDSTOP
***************************/

import com.gamepackage.tilemap.layer.*;

class com.gamepackage.tilemap.layer.PatternLayer
	implements com.gamepackage.tilemap.Layer, com.gamepackage.util.Loadable
{
	private var parent: MovieClip;
	private var depth: Number;
	private var cols: Number;
	private var rows: Number;
	private var tilesize: Number;
	private var ratio: Number;
	private var linkageId: String;
	
	private var timeline: MovieClip;

	private var x: Number, y: Number;
	
	private var ttx: Number, tty: Number;
	private var clips: Array;
	private var jx: Number;
	private var jy: Number;

	function PatternLayer( parent: MovieClip, depth: Number, cols: Number, rows: Number, tilesize: Number, ratio: Number, linkageId: String )
	{
		this.parent = parent;
		this.depth = depth;
		this.cols = cols;
		this.rows = rows;
		this.tilesize = tilesize;
		this.ratio = ratio;
		this.linkageId = linkageId;
		
		init();
	}
	
	private function init( Void ): Void
	{
		//-- CREATE TIMELINE --//
		timeline = parent.createEmptyMovieClip( linkageId , depth );
	}
	
	function create( Void ): Void
	{
		//-- BUILD CLIPS --//
		var i: Number = 0;
		var rx, ry;
		
		for( ry = 0 ; ry <= rows ; ry++ )
		{
			for( rx = 0 ; rx <= cols ; rx++ )
			{
				timeline.attachMovie(
					linkageId,
					i.toString(),
					i++,
					{
						_x: rx * tilesize,
						_y: ry * tilesize
					}
				)
			}
		}
	}
	
	function moveTo( x: Number, y: Number ): Void
	{
		//-- MOVE TIMELINE --//
		timeline._x = -x % tilesize;
		timeline._y = -y % tilesize;
	}
	
	function getLayerWidth( Void ): Number
	{
		return cols * ratio * tilesize;
	}
	
	function getLayerHeight( Void ): Number
	{
		return rows * ratio * tilesize;
	}
	
	function getX( Void ): Number
	{
		return x;
	}
	
	function getY( Void ): Number
	{
		return y;
	}
	
	function getLoaderClip( Void ): MovieClip
	{
		return timeline;
	}
}
















